package com.haiyou.dc.guava;

import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.var;

import java.util.Map;

/**
 * 不可变集合
 *
 * @author pc
 */
public class ImmutableMapDemo {

    public static void main(String[] args) {
//        ImmutableMap.Builder<String, RentValue> builder = ImmutableMap.builder();
//        builder.put("*-1000", new RentValue("*-1000", -1, 1000));
//        builder.put("1000-3000", new RentValue("1000-3000", 1000, 3000));
//        builder.put("3000-*", new RentValue("3000-*", 3000, -1));


        Map<String,Object> immutableMap = new ImmutableMap.Builder<String,Object>()
                .put("k1","v1")
                .put("k2","v2")
                .build();

        //会抛出java.lang.UnsupportedOperationException
        immutableMap.put("k1","v3");



    }

    @AllArgsConstructor
    @Data
    static class RentValue {
        private String key;
        private Integer min;
        private Integer max;
    }

}
